package com.zsck.zsgy.ui.main.fragment.mine

import androidx.lifecycle.MutableLiveData
import com.zsck.zsgy.api.ApiService
import com.zsck.zsgy.base.BaseRepository
import com.zsck.zsgy.http.RetrofitManager
import com.zsck.zsgy.http.exception.ApiException
import com.zsck.zsgy.ui.main.ContentConfig
import com.zsck.zsgy.ui.main.bean.MsgNumberBean
import com.zsck.zsgy.ui.main.bean.UserInfoBean
import kotlinx.coroutines.CoroutineScope

class MineRepoo(
    coroutineScope: CoroutineScope,
    errorLiveData: MutableLiveData<ApiException>
) :
    BaseRepository(coroutineScope, errorLiveData) {


    fun getUserinfo(userInfo: MutableLiveData<UserInfoBean>) {

        launch(block = {
            RetrofitManager.getApiService(ApiService::class.java)
                .getUserInfo()
                .data
        }, success = {
            userInfo.postValue(it)
        })
    }

    fun getMessage(msgInfo: MutableLiveData<MsgNumberBean>) {
        launch(block = {
            RetrofitManager.getApiService(ApiService::class.java)
                .msgInfo()
                .data
        }, success = {
            msgInfo.postValue(it)
        })
    }

    fun getConfigList(contentConfig: MutableLiveData<List<ContentConfig>>) {
        var body = HashMap<String, Any>()
        body.put("configLoations", 8)
        launch(block = {
            RetrofitManager.getApiService(ApiService::class.java)
                .mineConfigShowList(body)
                .data
        }, success = {
            contentConfig.postValue(it)
        })
    }
}